//
//  DetailCaculateView.m
//  YIJU2.0HD
//
//  Created by URANUS on 16/5/16.
//  Copyright © 2016年 Mr.X. All rights reserved.
//

#import "DetailCaculateNavView.h"
#import "Macro.h"


@interface DetailCaculateNavView ()
@property (nonatomic, strong)UILabel *titleLabel;//title
@property (nonatomic, strong)UIButton *detailBtn;//详情按钮
@property (nonatomic, strong)UIView *lineView;//分割线


@end

@implementation DetailCaculateNavView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self == [super initWithFrame:frame]) {
        [self setUpContaints];
        
    }
    return self;
}

- (void)setUpContaints {
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top);
        make.left.equalTo(self.mas_left);
        make.width.equalTo(self.mas_width);
        make.height.equalTo(self.mas_height);
    }];
    
    [self.detailBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_top).offset(15);
        make.right.equalTo(self.titleLabel.mas_right).offset(-10);
        make.width.equalTo(@(80));
        make.bottom.equalTo(self.titleLabel.mas_bottom).offset(-10);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom);
        make.left.equalTo(self.mas_left);
        make.right.equalTo(self.mas_right);
        make.height.equalTo(@(0.5f));
    }];
}

#pragma mark - resbonse events 
- (void)handleDetailAction:(UIButton *)button {
    if (self.PayBackAction != nil) {
        self.PayBackAction();
    }

}

#pragma mark - getter
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = [UIColor blackColor];
        _titleLabel.font = kTitle_Font;
        _titleLabel.backgroundColor = [UIColor clearColor];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.userInteractionEnabled = YES;
        [self addSubview:_titleLabel];
    }
    return _titleLabel;
}

- (UIButton *)detailBtn {
    if (!_detailBtn) {
        _detailBtn = [UIButton btnWithTitle:self.BtnTitleString];
        [_detailBtn setTitleColor:[UIColor darkGrayColor] forState:0];
        [_detailBtn addTarget:self action:@selector(handleDetailAction:) forControlEvents:UIControlEventTouchUpInside];
        [_titleLabel addSubview:_detailBtn];
    }
    return _detailBtn;
}

- (UIView *)lineView {
    if (!_lineView) {
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = [UIColor colorWithRed:0.7137 green:0.7373 blue:0.7608 alpha:1.0];
        [self addSubview:_lineView];
    }
    return _lineView;
}

- (void)setNavTitleString:(NSString *)NavTitleString {
    _titleLabel.text = NavTitleString;
}

- (void)setBtnTitleString:(NSString *)BtnTitleString {
    [_detailBtn setTitle:BtnTitleString forState:0];
}

- (void)setIsBtnShow:(BOOL)isBtnShow {
    if (_isBtnShow == YES) {
        _detailBtn.hidden = NO;
    } else {
        _detailBtn.hidden = YES;
    }
}

@end
